#include<iostream>
#include<mutex>

//探讨资源锁的问题
/*禁用复制函数和赋值操作符简单实现以对象管理资源型的加锁问题*/
/*或者是使用shared_ptr并指定删除器，达到reference counting pointers的效果*/
class Lock
{   
    public:
        explicit Lock(){mutex_->lock();std::cout<<"locked"<<std::endl;};
        Lock(const Lock&) = delete;
        void operator=(const Lock&) = delete;
        ~Lock(){mutex_->unlock();std::cout<<"unlocked"<<std::endl;};
    private:
    std::mutex *mutex_;
};


void Test()
{
    Lock a;
    std::cout << "Other operator." <<std::endl;
}


int main(int argc, char const *argv[])
{
    Test();
    Test();
    Test();
    Test();
    Test();

    return 0;
}
